package com.ujoku.service.impl;

import com.labillusion.core.database.base.mybatis.dao.BaseDao;
import com.labillusion.core.database.base.mybatis.service.base.impl.BaseServiceImpl;
import com.ujoku.dao.FavoriteDao;
import com.ujoku.domain.Favorite;
import com.ujoku.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Andy.Lian on 2015/1/28.
 */
@Service
public class FavoriteServiceImpl extends BaseServiceImpl<Favorite> implements FavoriteService<Favorite> {
    @Autowired
    private FavoriteDao favoriteDao;

    @Override
    protected BaseDao<Favorite> getBaseDao() {
        return favoriteDao;
    }

    @Override
    public List<Favorite> getFavoritesByUserId(int user_id){
        Map<String,Object> map = new HashMap<>();
        map.put("user_id", user_id);
        return this.selectList(map);
    }

    @Override
    public Favorite getFavoriteGoodsByUserId(int user_id,int goods_id){
        Map<String,Object> map = new HashMap<>();
        map.put("user_id", user_id);
        map.put("goods_id",goods_id);
        return this.selectOne(map);
    }

    @Override
    public int deleteFavoriteByGoodsId(int user_id, String goods_id){
        Map<String,Object> map = new HashMap<>();
        map.put("user_id", user_id);
        map.put("goods_id",goods_id);
        return this.delete(map);
    }
}
